package com.stylefeng.guns.modular.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.WithdrawOrder;
import com.stylefeng.guns.modular.pay.model.WithdrawtAccount;
import com.stylefeng.guns.modular.pay.service.IWithdrawOrderService;

/**
 * 提现订单控制器
 *
 * @author fengshuonan
 * @Date 2018-09-11 17:00:24
 */
@Controller
@RequestMapping("/withdrawOrder")
public class WithdrawOrderController extends BaseController {

    private String PREFIX = "/pay/withdrawOrder/";

    @Autowired
    private IWithdrawOrderService withdrawOrderService;

    /**
     * 跳转到提现订单首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "withdrawOrder.html";
    }

    /**
     * 跳转到添加提现订单
     */
    @RequestMapping("/withdrawOrder_add")
    public String withdrawOrderAdd() {
        return PREFIX + "withdrawOrder_add.html";
    }

    /**
     * 跳转到修改提现订单
     */
    @RequestMapping("/withdrawOrder_update/{withdrawOrderId}")
    public String withdrawOrderUpdate(@PathVariable Integer withdrawOrderId, Model model) {
        WithdrawOrder withdrawOrder = withdrawOrderService.selectById(withdrawOrderId);
        model.addAttribute("item",withdrawOrder);
        LogObjectHolder.me().set(withdrawOrder);
        return PREFIX + "withdrawOrder_edit.html";
    }

    /**
     * 获取提现订单列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(WithdrawOrder order) {
    	Page<WithdrawOrder> page = new PageFactory<WithdrawOrder>().defaultPage();
    	List<WithdrawOrder> result = withdrawOrderService.selectList(order);
        page.setRecords(result);
        return super.packForBT(page);
    }

    /**
     * 新增提现订单
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(WithdrawOrder withdrawOrder) {
        withdrawOrderService.insert(withdrawOrder);
        return SUCCESS_TIP;
    }

    /**
     * 删除提现订单
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer withdrawOrderId) {
        withdrawOrderService.deleteById(withdrawOrderId);
        return SUCCESS_TIP;
    }
    
    
    /**
     * 同步
     */
    @RequestMapping(value = "/syn")
    @ResponseBody
    public Object syn(@RequestParam Integer withdrawOrderId) {
        withdrawOrderService.syn(withdrawOrderId);
        return SUCCESS_TIP;
    }

    /**
     * 修改提现订单
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(WithdrawOrder withdrawOrder) {
        withdrawOrderService.updateById(withdrawOrder);
        return SUCCESS_TIP;
    }

    /**
     * 提现订单详情
     */
    @RequestMapping(value = "/detail/{withdrawOrderId}")
    @ResponseBody
    public Object detail(@PathVariable("withdrawOrderId") Integer withdrawOrderId) {
        return withdrawOrderService.selectById(withdrawOrderId);
    }
}
